package ragserverengine.milvus.core

import io.milvus.v2.client.MilvusClientV2;
import io.milvus.v2.client.ConnectConfig;

class MilvusClient(
    private val host: String = "localhost",
    private val port: Int = 19530
) {
    private lateinit var clientv2: MilvusClientV2

    // 使用v2 client
    fun connectV2() {
        val connectConfig = ConnectConfig.builder().uri("$host:$port").build()
        clientv2 = MilvusClientV2(connectConfig)

        print("Connected to MilvusV2 at $host:$port")
    }

    fun isConnectedV2(): Boolean {
        return ::clientv2.isInitialized
    }

    fun getClientV2(): MilvusClientV2 {
        if (!isConnectedV2()) {
            throw IllegalStateException("Milvus client not connected.")
        }
        return clientv2
    }

    fun cloasV2(){
        if (::clientv2.isInitialized){
            clientv2.close()
            println("Milvus connection closed.")
        }
    }
}
